/**
 * @param {number[]} nums
 * @return {number}
*/
var maxSubArray = function(nums) {
  const dp = new Array(nums.length).fill(-10001);
  dp[0] = nums[0];
  for(let i = 1; i < nums.length; i++) {
    dp[i] = nums[i] + Math.max(0, dp[i - 1]);
  }
  return Math.max(...dp);
};
let nums = [-2,1,-3,4,-1,2,1,-5,4];
console.log(maxSubArray(nums));
nums = [1];
console.log(maxSubArray(nums));
nums = [5,4,-1,7,8];
console.log(maxSubArray(nums));
